//
//  BwtBannerAdManager.m
//  bwt_ad_flutter
//
//  Created by 帅 on 2025/6/20.
//

#import "BwtBannerAdManager.h"
#import "BwtBannerAd.h"
#import "BwtAdLogManager.h"
@implementation BwtBannerAdManager


+ (BwtBannerAdManager *)getBwtBannerAdManager {
    static BwtBannerAdManager *bwtBannerAdManager;
    if(!bwtBannerAdManager) {
        bwtBannerAdManager = [[BwtBannerAdManager alloc] init];
        [bwtBannerAdManager initData];
    }
    return bwtBannerAdManager;
}
- (void)initData{
    if (!_bannerAdMap) {
        _bannerAdMap = [[NSMutableDictionary alloc] initWithCapacity:0];
    }
}

- (void)loadBannerAd:(AdParams*)adParams isRequestIdfa:(bool)isRequestIdfa {
    BwtBannerAd *ad = [[BwtBannerAd alloc] init];
    ad.adParams = adParams;
    ad.isRequestIdfa = isRequestIdfa;
    
    NSString *adId = adParams.adId;
    [_bannerAdMap setObject:ad forKey:adId];
    
    [[BwtAdLogManager getBwtAdLogManager] log:@"开始加banner广告, adId: %@", adParams.adId];
    [ad loadBannerAd];
}

- (UIView *)getBannerAdView:(NSString*)adId{
    if (adId) {
        BwtBannerAd *bannerAd = _bannerAdMap[adId];
        if (bannerAd) {
            return bannerAd.bannerView;
        }
    }
    return nil;
}

- (void)releaseAd:(NSString*)adId{
    if (adId) {
        BwtBannerAd *_bwtBannerAdAd = _bannerAdMap[adId];
        if (_bwtBannerAdAd) {
            [_bwtBannerAdAd releaseAd];
            [_bannerAdMap removeObjectForKey:adId];
            
            [[BwtAdLogManager getBwtAdLogManager] log:@"信息流模板广告已释放, adId: %@", adId];
        }
    }
}

@end
